package com.zqs.controller;

import com.zqs.entity.Hire;
import com.zqs.service.HireService;
import com.zqs.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 租车页
 */
@CrossOrigin
@RestController
@RequestMapping("hires")
public class HireController extends BaseController{

    @Autowired
    private HireService hireService;

    // 添加租车订单  json{name,phone,day,pid,money}
    @PostMapping("add_hire")
    public JsonResult<Void> addHire(@RequestBody Hire hire, HttpSession session){
        hireService.addHire(hire,getSessionUid(session));
        return new JsonResult<>(OK);
    }

    @GetMapping("getHireByUid")
    public JsonResult<List<Hire>> getHireByUid(HttpSession session){
        Integer uid = getSessionUid(session);
        List<Hire> dataList = hireService.getHire(uid);
        return new JsonResult<>(OK,dataList);
    }
}
